package com.example.ItPhotoAlbumCloud.controller;

import com.example.ItPhotoAlbumCloud.Service.ItPhotoAlbumCloudUserService;
import com.example.ItPhotoAlbumCloud.utils.CommonTemplate;
import com.alibaba.fastjson.JSONObject;
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;

/**
 * 云相册用户HTTP请求控制器
 *  小仙 创建人  2023-03-12 08:36:32.
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/ItPhotoAlbumCloudUser/api/")
public class ItPhotoAlbumCloudUserController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ItPhotoAlbumCloudUserController.class);

    @Resource
    private ItPhotoAlbumCloudUserService ItPhotoAlbumCloudUserService;

    /**
     * 通过邮箱注册
     * @param request
     * @return
     */
    @RequestMapping(value = "create.json", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object create(@RequestBody JSONObject request){
        return CommonTemplate.run(LOGGER, new CommonTemplate() {
            @Override
            protected Object business() {
                return ItPhotoAlbumCloudUserService.create(request);
            }
        }, request);
    }




    /**
     * 修改密码
     * @param request
     * @return
     */
    @RequestMapping(value = "modify.json", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object modify(@RequestBody JSONObject request){
        return CommonTemplate.run(LOGGER, new CommonTemplate() {
            @Override
            protected Object business() {
                return ItPhotoAlbumCloudUserService.modify(request);
            }
        }, request);
    }

    /**
     * 分页查询
     * @param request
     * @return
     */
    @RequestMapping(value = "pageQuery.json", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object pageQuery(@RequestBody JSONObject request){
        return CommonTemplate.run(LOGGER, new CommonTemplate() {
            @Override
            protected Object business() {
                return ItPhotoAlbumCloudUserService.pageQuery(request);
            }
        }, request);
    }

    /**
     * 通过邮箱以及密码登录
     * @param request
     * @return
     */
    @RequestMapping(value = "queryByEmail.json", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object queryById(@RequestBody JSONObject request){
        return CommonTemplate.run(LOGGER, new CommonTemplate() {
            @Override
            protected Object business() {
                return ItPhotoAlbumCloudUserService.queryByEmail(request);
            }
        }, request);
    }

    /**
     * 通过邮箱发送验证码
     * @param request
     * @return
     */
    @RequestMapping(value = "sendEmail.json", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object sendHtmlEmail(@RequestBody JSONObject request) {
        return CommonTemplate.run(LOGGER, new CommonTemplate() {
            @Override
            protected Object business() throws javax.mail.MessagingException {
                return ItPhotoAlbumCloudUserService.sendHtmlEmail(request);
            }
        }, request);
    }

}

